import Axios from './axios'

var login = function(loading, fn) {
  var data = {
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
      "user": "Admin",
      "password": "zabbix"
    },
    "id": 1,
    "auth": null
  }
  Axios.post('/zabbix/api_jsonrpc.php', data).then(
    res => {
      if (res.result) {
        localStorage.setItem('auth', res.result);
        localStorage.setItem('currentId', res.id);
        loading.close();
        fn()
          // return true;
      } else {
        login();
      }
    },
    err => {
      console.log(err);
      login();
    }
  )
}

export default login;